package file1;

import java.util.*;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/4/12
 * \* Time: 13:19
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class Demo4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String [] pp = str.split("-");//4444-jokerJOKER，将这个字符串以-分隔开   4 4 4 4   joker JOKER
        String [] p1 = pp[0].split(" ");
        String [] p2 = pp[1].split(" ");
        String p = "34567891JQKA2";
        if(pp[0].equals("joker JOKER") || pp[1].equals("joker JOKER")){
            System.out.println("joker JOKER");
        }else if(p1.length == p2.length){
            if(p.indexOf(p1[0].substring(0,1)) > p.indexOf(p2[0].substring(0,1))){
                System.out.println(pp[0]);
            }else if(p1[0].equals("JOKER") || p2[0].equals("JOKER")){
                System.out.println("JOKER");
            }else if(p1[0].equals("joker") || p2[0].equals("joker")){
                System.out.println("joker");
            }else {
                System.out.println(pp[1]);
            }
        }else if(p1.length == 4){
            System.out.println(pp[0]);
        }else if(p2.length == 4){
            System.out.println(pp[1]);
        }else{
            System.out.println("ERROR");
        }
    }





    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        if(k <= 0 || n < k){
            return res;
        }
        Deque<Integer> path = new ArrayDeque<>();
        dfs(n,k,1,path,res);
        return res;
    }

    private void dfs(int n, int k, int begin, Deque<Integer> path, List<List<Integer>> res) {
        if(path.size()==k){
            res.add(new ArrayList<>(path));
            return;
        }
        for(int i =begin;i<= n;i++){
            path.addLast(i);
            dfs(n,k,i+1,path,res);
            path.removeFirst();
        }
    }


    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for(int i =0; i <n; i++){
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        System.out.println(count(arr,n,0,0,1));
    }

    private static int count(int[] arr, int n, int pos, int sum, int multi) {
        int count = 0;
        for (int i =pos;i<n;i++){
            sum += arr[i];
            multi *= arr[i];
            if(sum > multi){
                count = count + 1 + count(arr,n,i+1,sum,multi);
            }else if(arr[i] == 1){
                count = count + count(arr,n,i+1,sum,multi);
            }else {
                break;
            }
            sum = sum -arr[i];
            multi = multi/arr[i];
            while (i<n-1 && arr[i] == arr[i+1]){
                i++;
            }
        }
        return count;
    }
}
